﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.Data;
using Maticsoft.Common;
using System.Drawing;


namespace Admin.Search
{
    public partial class ProjectSearch : System.Web.UI.Page
    {
        ChinaSoft.BLL.BLL_tb_MidSoft_CareProject bll = new ChinaSoft.BLL.BLL_tb_MidSoft_CareProject();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                BindData();
            }
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            BindData();
        }

        #region gridView

        public void BindData()
        {
            #region
            //if (!Context.User.Identity.IsAuthenticated)
            //{
            //    return;
            //}
            //AccountsPrincipal user = new AccountsPrincipal(Context.User.Identity.Name);
            //if (user.HasPermissionID(PermId_Modify))
            //{
            //    gridView.Columns[6].Visible = true;
            //}
            //if (user.HasPermissionID(PermId_Delete))
            //{
            //    gridView.Columns[7].Visible = true;
            //}
            #endregion
            StringBuilder strWhere = new StringBuilder();
            if (txtProjectName.Text.Trim() != "")
            {
                strWhere.AppendFormat(" and ProjectName like '%{0}%'", txtProjectName.Text.Trim());
            }
            if (txtProjectNumber.Text.Trim() != "")
            {
                strWhere.AppendFormat(" and ProjectNumber like '%{0}%'", txtProjectNumber.Text.Trim());
            }
            if (ddlProjectSpecialty.SelectedItem.Text != "")
            {
                strWhere.AppendFormat(" and ProjectSpecialty='{0}'", ddlProjectSpecialty.SelectedItem.Text);
            }
            if (txtArea.Text.Trim() != "")
            {
                strWhere.AppendFormat(" and Area like '%{0}%'", txtArea.Text.Trim());
            }
            if (txtCustomer.Text.Trim() != "")
            {
                strWhere.AppendFormat(" and Customer like '%{0}%'", txtCustomer.Text.Trim());
            }
            if (txtDepartMent.Text.Trim() != "")
            {
                strWhere.AppendFormat(" and DepartMent like '%{0}%'", txtDepartMent.Text.Trim());
            }
            if (ddlState.SelectedItem.Text != "")
            {
                strWhere.AppendFormat(" and ProjectState='{0}'", ddlState.SelectedItem.Text);
            }
            try
            {
                lblCount.Text = (new ChinaSoft.BLL.Common.Pager()).RecordCount("tb_MidSoft_ProjectInfo", strWhere.ToString()).ToString();
                ChinaSoft.BLL.Common.Pager.BindGridView(gridView, AspNetPager1, "tb_MidSoft_ProjectInfo", "ProjectInfoId", "*", strWhere.ToString(), "CreateTime desc", "");
            }
            catch (Exception ex)
            {
                Response.Write("数据库错误：" + ex.Message);
                Response.End();
            }
        }
        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            BindData();
        }
        protected void gridView_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            gridView.PageIndex = e.NewPageIndex;
            BindData();
        }
        protected void gridView_OnRowCreated(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.Header)
            {
                e.Row.Cells[0].Text = "<input type=\"checkbox\" id=\"cbSelectAll\" name=\"cbSelectAll\" onclick=\"javascript:checkJs(this.checked);\" />";
            }
        }
        protected void gridView_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                //LinkButton linkbtnDel = (LinkButton)e.Row.FindControl("LinkButton1");
                //linkbtnDel.Attributes.Add("onclick", "return confirm(\"你确认要删除吗\")");

                //object obj1 = DataBinder.Eval(e.Row.DataItem, "Levels");
                //if ((obj1 != null) && ((obj1.ToString() != "")))
                //{
                //    e.Row.Cells[1].Text = obj1.ToString();
                //}
                Label lblState = (Label)e.Row.FindControl("Label1");
                switch (lblState.Text)
                {
                    case "0":
                        lblState.Text = "未完工";
                        break;
                    case "1":
                        lblState.Text = "进行中";
                        break;
                    case "2":
                        lblState.Text = "已完工";
                        break;
                    default:
                        break;
                }
            }
        }


        #endregion
    }
}